home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
tvdmx.exe
/
TVDMXCOL.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1992-07-16
|
13KB
|
437 lines
{■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
{ }
{ tvDMXCOL --Collection Data Editing Unit }
{ tvDMX --data editing project }
{ }
{ Copyright (c) 1992 Randolph Beck }
{ P.O. Box 56-0487 }
{ Orlando, FL 32856 }
{ CIS: 72361,753 }
{ }
{■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■}
Unit tvDMXCOL;
{$B-,D-,R-,O+,X+,V- }
interface
uses
Objects, Drivers, Memory, Views, App, MsgBox,
RSet, DmxGizma, tvDMX, StdDMX;
const
cmDMX_Reset = cmDMX + 49;
type
PDmxCollectView = ^TDmxCollectView;
PDmxCollector = ^TDmxCollector;
PDmxCollectViewWin = ^TDmxCollectViewWin;
PDmxCollectorWin = ^TDmxCollectorWin;
TDmxCollectView = OBJECT (TDmxScroller)
constructor Init (ATemplate : string; var AData;
var Bounds : TRect; ALabels : PView;
AHScrollBar,AVScrollBar : PScrollBar);
procedure InitData (var AData ); VIRTUAL;
procedure SetState (AState : word; Enable : boolean); VIRTUAL;
function DataAt (RecNum : integer) : pointer; VIRTUAL;
end;
TDmxCollector = OBJECT (TDmxEditor)
NewDataRec : pointer;
MaxCount : integer;
MemWarning : boolean;
procedure LoadStruct (var S : TStream); VIRTUAL;
procedure StoreStruct (var S : TStream); VIRTUAL;
procedure InitData (var AData ); VIRTUAL;
procedure InitNewDataRec;
procedure DoneData; VIRTUAL;
procedure HandleEvent (var Event : TEvent); VIRTUAL;
function Valid (Command : word) : boolean; VIRTUAL;
procedure SetState (AState : word; Enable : boolean); VIRTUAL;
function DataAt (RecNum : integer) : pointer; VIRTUAL;
procedure SetupRecord; VIRTUAL;
procedure EvaluateRecord; VIRTUAL;
procedure ZeroizeRecord; VIRTUAL;
end;
TDmxCollectViewWin = OBJECT (TDmxViewer)
constructor Init (var Bounds : TRect; ATitle : TTitleStr;
ANumber : integer; ATemplate : string;
ACollection : PCollection; var ALabels : string);
procedure InitDMX (ATemplate : string; var AData;
ALabels, ARecInd : PDmxLink;
BSize : longint); VIRTUAL;
end;
TDmxCollectorWin = OBJECT (TDmxWindow)
constructor Init (var Bounds : TRect;
ATitle : TTitleStr; ANumber : integer;
ATemplate : string; ACollection : PCollection;
BSize : integer; var ALabels : string; IndLen : integer);
procedure InitDMX (ATemplate : string; var AData;
ALabels, ARecInd : PDmxLink;
BSize : longint); VIRTUAL;
end;
function fldObjectVMT (Obj : PObject) : string;
{ template prefix to generate a VMT identifier
for collections of TObject derivatives
}
procedure ResetCollection (Collection : PCollection);
{ adjust the size of the database }
implementation
{ ══════════════════════════════════════════════════════════════════════ }
function fldObjectVMT (Obj : PObject) : string;
begin
fldObjectVMT := ^H'c'^V + pchar(Obj)^ + #0^H'c'^V + pstring(Obj)^[1] + #0;
Dispose (Obj, Done);
end;
procedure ResetCollection (Collection : PCollection);
{ adjust the size of the database }
begin
Repeat
Until (Message (DeskTop, evBroadcast, cmDMX_Reset, Collection) = nil)
or (Collection^.Count > 0);
Message (DeskTop, evCommand, cmDMX_Reset, Collection);
end;
{ ══ TDmxCollectView ═══════════════════════════════════════════════════ }
constructor TDmxCollectView.Init (ATemplate : string; var AData;
var Bounds : TRect;
ALabels : PView;
AHScrollBar,AVScrollBar : PScrollBar);
begin
TDmxScroller.Init (ATemplate, AData, 0, Bounds, ALabels, AHScrollBar, AVScrollBar);
end;
procedure TDmxCollectView.InitData (var AData );
begin
TDmxScroller.InitData (AData);
DataBlockSize := (RecordSize * PCollection (WorkingData)^.Count);
end;
procedure TDmxCollectView.SetState (AState : word; Enable : boolean);
begin
If Enable and (AState = sfFocused) and
(DataBlockSize <> RecordSize * PCollection (WorkingData)^.Count) then
DataBlockSize := RecordSize * PCollection (WorkingData)^.Count;
TDmxScroller.SetState (AState, Enable);
end;
function TDmxCollectView.DataAt (RecNum : integer) : pointer;
begin
If (PCollection (WorkingData)^.Count <= RecNum) then
DataAt := nil
else
DataAt := PCollection (WorkingData)^.At (RecNum);
end;
{ ══ TDmxCollector ═════════════════════════════════════════════════════ }
procedure TDmxCollector.LoadStruct (var S : TStream);
begin
TDmxEditor.LoadStruct (S);
S.Read (MaxCount, sizeof (MaxCount));
InitNewDataRec;
end;
procedure TDmxCollector.StoreStruct (var S : TStream);
begin
TDmxEditor.StoreStruct (S);
S.Write (MaxCount, sizeof (MaxCount));
end;
procedure TDmxCollector.InitData (var AData );
{ this method is called during initialization }
begin
TDmxEditor.InitData (AData);
{ Note that the given database size is used for max record count. }
Move (DataBlockSize, MaxCount, 2);
DataBlockSize := (RecordSize * PCollection (WorkingData)^.Count);
If (MaxCount = 0) or (PCollection (WorkingData)^.Count < MaxCount) then
DataBlockSize := DataBlockSize + RecordSize;
InitNewDataRec;
end;
procedure TDmxCollector.DoneData;
{ this method is called during termination }
begin
TDmxEditor.DoneData;
If (NewDataRec <> nil) then FreeMem (NewDataRec, RecordSize);
end;
procedure TDmxCollector.InitNewDataRec;
{ initialize a temporary data object for new records }
begin
If (RecordSize > 0) then
begin
GetMem (NewDataRec, RecordSize);
RecordData := NewDataRec;
TDmxEditor.ZeroizeRecord;
RecordAltered := FALSE;
FieldAltered := FALSE;
end
else
NewDataRec := nil;
end;
procedure TDmxCollector.HandleEvent (var Event : TEvent);
begin
TDmxEditor.HandleEvent (Event);
If (Event.What and evMessage <> 0) and (Event.Command = cmDMX_Reset) and
(Event.InfoPtr = WorkingData) then
begin
DataBlockSize := RecordSize;
DataBlockSize := DataBlockSize * PCollection (WorkingData)^.Count;
If (MaxCount = 0) or (PCollection (WorkingData)^.Count < MaxCount) then
DataBlockSize := DataBlockSize + RecordSize;
If (DataBlockSize <= 0) and (Owner <> nil) and
(not GetState (sfFocused) or (Event.What = evCommand)) then
begin
Event.What := evCommand;
Event.Command := cmClose;
Event.InfoPtr := Owner;
end
else
begin
If RecordSelected then
begin
FieldAltered := FALSE;
RecordAltered := FALSE;
EvaluateField;
EvaluateRecord;
If (CurrentRecord >= (DataBlockSize div RecordSize)) and
(DataBlockSize > 0) then
CurrentRecord := pred (DataBlockSize div RecordSize);
SetupRecord;
SetupField;
end;
SetLimit (Limit.X, DataBlockSize div RecordSize);
DrawView;
If (Event.What = evCommand) then ClearEvent (Event);
end;
end;
end;
function TDmxCollector.Valid (Command : word) : boolean;
var V : boolean;
begin
V := TDmxEditor.Valid (Command);
If V and (Command = cmValid) and
((WorkingData = nil) or (DataBlockSize < RecordSize) or (RecordSize <= 0)) then
begin
MessageBox ('No data available.', nil, mfError or mfOKButton);
Valid := FALSE;
end
else
Valid := V;
end;
procedure TDmxCollector.SetState (AState : word; Enable : boolean);
{ resets the DataBlockSize if the collection's limit has changed }
begin
If Enable and (AState = sfFocused) and
(DataBlockSize <> RecordSize * succ (PCollection (WorkingData)^.Count)) then
begin
DataBlockSize := RecordSize * PCollection (WorkingData)^.Count;
If (MaxCount = 0) or (PCollection (WorkingData)^.Count < MaxCount) then
DataBlockSize := DataBlockSize + RecordSize;
end;
TDmxEditor.SetState (ASt